package com.huazai.ServletStudy;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;

@WebServlet(name = "test",value = "/test")
public class testServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");

        System.out.println(request.getParameter("username"));
        System.out.println(request.getContextPath());


//        Enumeration<String> names = request.getParameterNames();
//        response.setContentType("text/html;charset=UTF-8");
//        PrintWriter pw = response.getWriter();
//        while( names.hasMoreElements() ) {
//            pw.print( names.nextElement().toString() + "<br>");
//        }
//
//        String aihao = request.getParameter("aihao");
//        pw.print(aihao + "<br>");
//        String[] values = request.getParameterValues("aihao");
//        for (String value : values) {
//            pw.print(value + "<br>");
//        }
//
//        Map<String, String[]> parameterMap = request.getParameterMap();
//
//        Collection<String[]> collection = parameterMap.values();
//        Iterator<String[]> it = collection.iterator();
//        while( it.hasNext() ) {
//            String[] next = it.next();
//            for (String s : next) {
//                pw.print(s + "<br>");
//            }
//        }

//        Date nowDate = new Date();
//        request.setAttribute("sysTime",nowDate);
//        Object sysTime = request.getAttribute("sysTime");
//        pw.print(sysTime + "  为当前时间 <br>");


//        request.getRequestDispatcher("/index.jsp").forward(request, response);


    }
}
